/* eslint-disable vue/require-default-prop */
<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon :icon-class="isScreenFull ? 'exit-fullscreen': 'fullscreen'" class="fullscreen" @click="toggleScreen" />
  </div>
</template>

<script>
// 导入局部组件必须在scrip里面导入,在App里面导入
export default {
// 组件名称
  name: 'ScreenFull',
  // 接收局部注册的组件
  components: {},
  // 组件参数接收来自父组件的数据
  props: {

  },
  // 组件数据
  data () {
    return {
      isScreenFull: false
    }
  },
  mounted () {
    document.addEventListener('fullscreenchange', e => {
      // 监听到屏幕变化，在回调中判断是否已退出全屏 如果已退出全屏 把本地状态修改为false
      const isFull = document.fullscreenElement
      if (!isFull) {
        this.isScreenFull = false
      }
    })
  },
  methods: {
    toggleScreen () {
      if (this.isScreenFull) {
        document.exitFullscreen()
      } else {
        document.documentElement.requestFullscreen()
      }
      this.isScreenFull = !this.isScreenFull
    }

  }
}
</script>
<style lang='scss' scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff !important;
  cursor: pointer !important;
}
</style>
